﻿using System.Collections.Generic;
using System.Linq;
using ServiceLibrary.Callbacks;

namespace ServiceLibrary
{
    public class PumpStation
    {
        private int _waterlevel;

        public int Id { get; private set; }
        public string IPAddress { get; private set; }
        public int Port { get; private set; }

        public IPumpStationCallback CallbackChannel { get; private set; }
        public Pump[] Pumps { get; private set; }

        public int Waterlevel
        {
            get { return _waterlevel; }
            set
            {
                _waterlevel = value;
                if (Changed != null)
                    Changed(this);
            }
        }

        public delegate void StationChangedEvent(PumpStation station);
        public event StationChangedEvent Changed;

        public PumpStation(int stationId, string ipAddress, int port, IEnumerable<PumpDTO> pumps, IPumpStationCallback callbackChannel)
        {
            Id = stationId;
            IPAddress = ipAddress;
            Port = port;
            CallbackChannel = callbackChannel;
            Pumps = pumps.Select(pump => new Pump(pump.Capacity) { Running = pump.Running }).ToArray();
        }
    }
}
